package com.jiuyun.filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter("/str")
public class HelloFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
//        System.out.println("初始化方法");
    }

    public void destroy() {
//        System.out.println("过滤器销毁的时候");
    }

    //执行过滤器  参数三个  请求 响应 过滤器链
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
//        System.out.println("正在过滤");
//        HttpServletResponse resp=(HttpServletResponse)response;
//        HttpServletRequest req=(HttpServletRequest)request;
//        String url=req.getRequestURI();
//        //取出请求中的参数
//       String name=request.getParameter("stname");
//        if ("admin".equals(name)||url.endsWith("login.jsp")){
//            chain.doFilter(request, response);
//        }else{
//
//            //跳转界面
//            resp.sendRedirect("/taobao/login.jsp");
//        }


//        String url=req.getServletPath();
//        String s=url.substring(url.lastIndexOf('.')+1, url.length());
//        String path=req.getServletContext().getContextPath();
//        System.out.println(path);
//        if(!(s.equals("jsp")||s.equals("action")||s.equals("png")||s.equals("jpg")||s.equals("gif")
//                ||s.equals("js")||s.equals("css"))){
//            //重定向到登陆界面
//            resp.sendRedirect("localhost:8080/"+path+"/error.jsp");
//        }else {
//            // pass the request along the filter chain
//            chain.doFilter(request, response);
//        }


    }
}
